package com.ruoyi.system.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.fastjson2.JSONArray;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.vo.OrderContrastDetailVo;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.IRxOrderContrastService;
import com.ruoyi.system.utils.PhpToJson;
import com.ruoyi.system.utils.node.CommissionNote2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 佣金对比批次Controller
 *
 * @author hjf
 * @date 2025-06-04
 */
@RestController
@RequestMapping("/hmk/contrast")
public class RxOrderContrastController extends BaseController {
    @Autowired
    private IRxOrderContrastService rxOrderContrastService;

    @Autowired
    private RxOrderContrastMapper rxOrderContrastMapper;

    @Autowired
    private RxOrderMapper rxOrderMapper;

    @Autowired
    private OrderContrastDetailMapper orderContrastDetailMapper;

    @Autowired
    private OrderContrastBusinessDetailMapper orderContrastBusinessDetailMapper;

    @Autowired
    private RxBusinessMapper bMapper;

    private static final String NO_ORDER_FOUND = "没有查到对应订单";
    private static final String COMMISSION_TYPE_MISMATCH = "佣金类型不匹配";
    private static final String IMMEDIATE_COMMISSION = "该订单为即返佣金";
    private static final String GANG_GANG = "--";
    private static final String SUCCESS = "成功";


    @PreAuthorize("@ss.hasPermi('hmk:contrast:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxOrderContrast rxOrderContrast) {
        startPage();
        List<RxOrderContrast> list = rxOrderContrastService.selectRxOrderContrastList(rxOrderContrast);
        return getDataTable(list);
    }


    @PreAuthorize("@ss.hasPermi('hmk:contrast:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxOrderContrastService.selectRxOrderContrastById(id));
    }


    @PreAuthorize("@ss.hasPermi('hmk:contrast:add')")
    @PostMapping
    public AjaxResult add(@RequestBody RxOrderContrast rxOrderContrast) {
        return toAjax(rxOrderContrastService.insertRxOrderContrast(rxOrderContrast));
    }


    @PreAuthorize("@ss.hasPermi('hmk:contrast:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody RxOrderContrast rxOrderContrast) {
        return toAjax(rxOrderContrastService.updateRxOrderContrast(rxOrderContrast));
    }


    @PreAuthorize("@ss.hasPermi('hmk:contrast:remove')")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        RxOrderContrast rxOrderContrast = rxOrderContrastService.selectRxOrderContrastById(id);
        if (null == rxOrderContrast) {
            throw new ServiceException("没有查到该订单!");
        }
        if (rxOrderContrast.getStatus() == 2) {
            throw new ServiceException("该订单已入账禁止删除!");
        }
        rxOrderContrastService.deleteRxOrderContrastByIds(id);
        orderContrastDetailMapper.deleteContrastId(rxOrderContrast.getBatch());
        orderContrastBusinessDetailMapper.deleteContrastId(rxOrderContrast.getBatch());
        return AjaxResult.success("删除成功!");
    }


    @PreAuthorize("@ss.hasPermi('hmk:contrast:list')")
    @GetMapping("/selectContrastDetailVoList")
    public TableDataInfo selectContrastDetailVoList(OrderContrastDetail orderContrastDetail) {
        startPage();
        List<OrderContrastDetailVo> list = orderContrastDetailMapper.selectOrderContrastDetailVoList(orderContrastDetail);
        return getDataTable(list);
    }

    @RepeatSubmit(interval = 30000)
    @PreAuthorize("@ss.hasPermi('hmk:contrast:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        long startTime = System.currentTimeMillis();
        ExcelUtil<OrderContrastExcelTemplate> util = new ExcelUtil(OrderContrastExcelTemplate.class);
        List<OrderContrastExcelTemplate> importList = util.importExcel(file.getInputStream());
        if (StringUtils.isNull(importList) || importList.size() == 0) {
            throw new ServiceException("导入数据不能为空！");
        }
        Set<String> identificationNumbers = importList.stream()
                .filter(contract -> StringUtils.isNotEmpty(contract.getIdentificationNumber()))
                .filter(contract -> contract.getChuYongMoney() != null && BigDecimal.ZERO.compareTo(contract.getChuYongMoney()) != 0)
                .map(OrderContrastExcelTemplate::getIdentificationNumber)
                .collect(Collectors.toSet());

        Map<String, RxOrder> orderMap = new HashMap<>();
        if (!identificationNumbers.isEmpty()) {
            List<RxOrder> orders = rxOrderMapper.getOrderListByIdentificationNumbers(identificationNumbers);
            orders.forEach(order -> orderMap.put(order.getIdentificationNumber(), order));
        }

        long time = System.currentTimeMillis();
        String timeStr = Long.toString(time);
        timeStr = timeStr.substring(timeStr.length() - 5);
        String uId = DateUtils.dateTimeNow() + timeStr;
        Date createTime = new Date();
        RxOrderContrast rxOrderContrast = new RxOrderContrast();
        rxOrderContrast.setStatus(1);
        rxOrderContrast.setBatch(uId);
        rxOrderContrast.setTime(time / 1000);
        rxOrderContrast.setCount(importList.size());
        rxOrderContrast.setDaoruManageId(SecurityUtils.getUserId());
        rxOrderContrastService.insertRxOrderContrast(rxOrderContrast);

        List<OrderContrastDetail> orderContrastDetails = new ArrayList<>();
        List<OrderContrastBusinessDetail> orderContrastBusinessDetails = new ArrayList<>();

        for (OrderContrastExcelTemplate contract : importList) {
            if (StringUtils.isEmpty(contract.getIdentificationNumber())) {
                continue;
            }
            if (null == contract.getChuYongMoney() || BigDecimal.ZERO.compareTo(contract.getChuYongMoney()) == 0) {
                continue;
            }
            try {
                RxOrder oldOrder = orderMap.get(contract.getIdentificationNumber());
                OrderContrastDetail ocd = new OrderContrastDetail();
                ocd.setOrderContrastId(uId);
                ocd.setPrice(contract.getChuYongMoney());
                ocd.setIdentificationNumber(contract.getIdentificationNumber());
                ocd.setPolicyName(contract.getPolicyName());
                ocd.setCreateTime(createTime);
                ocd.setResponse(SUCCESS);
                if (null == oldOrder) {
                    ocd.setResponse(NO_ORDER_FOUND);
                    ocd.setStatus(2);
                    orderContrastDetails.add(ocd);
                    continue;
                }
                ocd.setStatus(1);
                if (oldOrder.getCommissionpriceType() == 1) {
                    ocd.setCommissionPriceArr(GANG_GANG);
                    ocd.setStatus(2);
                    ocd.setResponse(IMMEDIATE_COMMISSION);
                } else if (oldOrder.getCommissionpriceType() == 2) {
                    String commissionJson = PhpToJson.phpToJson(oldOrder.getCommissionpriceArr());
                    List<CommissionNote2> commissionNotes = JSONArray.parseArray(commissionJson, CommissionNote2.class);
                    if (null != commissionNotes && commissionNotes.size() > 0) {
                        for (CommissionNote2 c : commissionNotes) {
                            c.setPrice(contract.getChuYongMoney().multiply(c.getLv().divide(new BigDecimal(100)))
                                    .setScale(2, RoundingMode.HALF_UP));
                            OrderContrastBusinessDetail detail = new OrderContrastBusinessDetail();
                            detail.setOrderContrastId(uId);
                            detail.setOrderId(oldOrder.getId());
                            detail.setIdentificationNumber(contract.getIdentificationNumber());
                            detail.setBusinessId(c.getId());
                            detail.setBusinessName(c.getName());
                            detail.setPrice(c.getPrice());
                            detail.setPolicyName(contract.getPolicyName());
                            detail.setStatus(1);
                            detail.setCreateTime(createTime);
                            orderContrastBusinessDetails.add(detail);
                        }
                        ocd.setCommissionPriceArr(commissionNotes.toString());
                    }
                } else {
                    ocd.setResponse(COMMISSION_TYPE_MISMATCH);
                }
                orderContrastDetails.add(ocd);
            } catch (Exception e) {
                OrderContrastDetail ocd = new OrderContrastDetail();
                ocd.setOrderContrastId(uId);
                ocd.setPrice(contract.getChuYongMoney());
                ocd.setIdentificationNumber(contract.getIdentificationNumber());
                ocd.setPolicyName(contract.getPolicyName());
                ocd.setResponse(e.getMessage());
                ocd.setCreateTime(createTime);
                ocd.setStatus(2);
                orderContrastDetails.add(ocd);
            }
        }
        if (!orderContrastDetails.isEmpty()) {
            int batchSize = 1000;
            for (int i = 0; i < orderContrastDetails.size(); i += batchSize) {
                int end = Math.min(i + batchSize, orderContrastDetails.size());
                List<OrderContrastDetail> batch = orderContrastDetails.subList(i, end);
                orderContrastDetailMapper.batchInsertOrderContrastDetail(batch);
            }
        }
        if (!orderContrastBusinessDetails.isEmpty()) {
            int batchSize = 1000;
            for (int i = 0; i < orderContrastBusinessDetails.size(); i += batchSize) {
                int end = Math.min(i + batchSize, orderContrastBusinessDetails.size());
                List<OrderContrastBusinessDetail> batch = orderContrastBusinessDetails.subList(i, end);
                orderContrastBusinessDetailMapper.batchInsertOrderContrastBusinessDetail(batch);
            }
        }
        List<OrderContrastDetail> successList = orderContrastDetails.stream()
                .filter(a -> a.getStatus() == 1)
                .collect(Collectors.toList());
        int failSize = orderContrastDetails.size() - successList.size();
        long endTime = System.currentTimeMillis() - startTime;
        return success("总共上传: " + orderContrastDetails.size() + " 成功: " + successList.size() + " 失败: " + failSize + " 总耗时:" + (endTime / 1000) + "秒");
    }


    @PermitAll
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<OrderContrastExcelTemplate> util = new ExcelUtil(OrderContrastExcelTemplate.class);
        util.importTemplateExcel(response, "对佣比例");
    }


    @PreAuthorize("@ss.hasPermi('hmk:contrast:export')")
    @RepeatSubmit
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderContrastDetail orderContrastDetail) {
        SysUser currentUser = SecurityUtils.getLoginUser().getUser();
        if (currentUser == null) {
            throw new ServiceException("用户未登录或会话已过期", 401);
        }
        if (StringUtils.isEmpty(orderContrastDetail.getOrderContrastId())) {
            throw new ServiceException("批次号必传");
        }
        OrderContrastDetail queryOrderContrastDetail = new OrderContrastDetail();
        queryOrderContrastDetail.setOrderContrastId(orderContrastDetail.getOrderContrastId());
        List<OrderContrastDetail> orderContrastDetails = orderContrastDetailMapper.selectOrderContrastDetailList(queryOrderContrastDetail);
        Set<String> identifications = orderContrastDetails.stream().map(m -> m.getIdentificationNumber()).collect(Collectors.toSet());
        if (identifications.size() > 0) {
            List<RxOrder> orderDataReplenish = rxOrderMapper.getOrderListsByIdentificationNumbers(identifications);
            Map<String, RxOrder> orderDataReplenishMap = orderDataReplenish.stream().collect(Collectors.toMap(RxOrder::getIdentificationNumber, order -> order,
                    (existing, replacement) -> existing));
            for (OrderContrastDetail o : orderContrastDetails) {
                RxOrder rxOrder = orderDataReplenishMap.get(o.getIdentificationNumber());
                if (null != rxOrder) {
                    o.setSerial(rxOrder.getSerial());
                    o.setTelnumber(rxOrder.getTelnumber());
                }
            }
            List<OrderContrastDetailVo> orderContrastDetailVos = orderContrastDetailMapper.selectOrderContrastDetailVoList(queryOrderContrastDetail);
            OrderContrastBusinessDetail queryContrastBusiness = new OrderContrastBusinessDetail();
            queryContrastBusiness.setOrderContrastId(orderContrastDetail.getOrderContrastId());
            List<OrderContrastBusinessDetail> orderContrastBusinessDetailList =
                    orderContrastBusinessDetailMapper.selectOrderContrastBusinessDetailList(queryContrastBusiness);

            Map<Long, String> bMaps = new HashMap<>();
            if (orderContrastBusinessDetailList.size() > 0) {
                RxBusiness rxBusiness = new RxBusiness();
                List<RxBusiness> rxBusinesses = bMapper.selectRxBusinessListSimple(rxBusiness);
                bMaps = rxBusinesses.stream().collect(Collectors.toMap(RxBusiness::getId, RxBusiness::getName));

            }
            for (OrderContrastBusinessDetail o : orderContrastBusinessDetailList) {
                RxOrder rxOrder = orderDataReplenishMap.get(o.getIdentificationNumber());
                if (null != rxOrder) {
                    o.setSerial(rxOrder.getSerial());
                    o.setTelnumber(rxOrder.getTelnumber());
                    o.setBusinessName(bMaps.get(o.getBusinessId()));
                }
            }
            try {
                String filename = "导出数据_" + DateUtils.dateTimeNow() + ".xlsx";
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
                WriteCellStyle headWriteCellStyle = new WriteCellStyle();
                WriteFont headWriteFont = new WriteFont();
                headWriteFont.setFontHeightInPoints((short) 10);
                headWriteCellStyle.setWriteFont(headWriteFont);
                ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
                HorizontalCellStyleStrategy styleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, Collections.emptyList());
                WriteSheet sheet1 = EasyExcel.writerSheet(1, "比对明细")
                        .head(OrderContrastDetail.class)
                        .registerWriteHandler(styleStrategy)
                        .build();
                excelWriter.write(orderContrastDetails, sheet1);
                WriteSheet sheet2 = EasyExcel.writerSheet(2, "商户总览")
                        .head(OrderContrastDetailVo.class)
                        .registerWriteHandler(styleStrategy)
                        .build();
                excelWriter.write(orderContrastDetailVos, sheet2);
                WriteSheet sheet3 = EasyExcel.writerSheet(3, "商户佣金明细")
                        .head(OrderContrastBusinessDetail.class)
                        .registerWriteHandler(styleStrategy)
                        .build();
                excelWriter.write(orderContrastBusinessDetailList, sheet3);
                excelWriter.finish();
            } catch (IOException e) {
                throw new ServiceException("导出失败：" + e.getMessage());
            }
        }
    }

    @PreAuthorize("@ss.hasPermi('hmk:contrast:ruZhang')")
    @PostMapping("/ruZhang")
    public AjaxResult ruZhang(@RequestBody OrderContrastBusinessDetail obd) {
        RxOrderContrast rxOrderContrast = rxOrderContrastMapper.selectRxOrderContrastByBatch(obd.getOrderContrastId());
        if (null == rxOrderContrast) {
            throw new ServiceException("没有查到对应的批次号");
        }
        OrderContrastBusinessDetail queryOBD = new OrderContrastBusinessDetail();
        queryOBD.setOrderContrastId(obd.getOrderContrastId());
        List<OrderContrastBusinessDetail> orderContrastBusinessDetails = orderContrastBusinessDetailMapper.selectOrderContrastBusinessDetailList(queryOBD);
        int batchSize = 1000;
        int totalSize = orderContrastBusinessDetails.size();
        for (int i = 0; i < totalSize; i += batchSize) {
            int end = Math.min(i + batchSize, totalSize);
            List<OrderContrastBusinessDetail> batch = orderContrastBusinessDetails.subList(i, end);
            logger.info("orderContrastBusinessDetails: {}/{}", end, orderContrastBusinessDetails.size());

            if (batch.size() > 0) {
                OrderContrastBusinessDetail queryObD = new OrderContrastBusinessDetail();
                queryObD.setRuzhangTime(obd.getRuzhangTime());
                List<OrderContrastBusinessDetail> ruZhangTimeReplicas = orderContrastBusinessDetailMapper.selectOrderContrastBusinessDetailList(queryObD);
                if (ruZhangTimeReplicas.size() > 0) {
                    Set<String> ruZhangIdentNumbers = ruZhangTimeReplicas.stream()
                            .map(OrderContrastBusinessDetail::getIdentificationNumber)
                            .collect(Collectors.toSet());

                    List<OrderContrastBusinessDetail> yiRuZhang = batch.stream()
                            .filter(item -> ruZhangIdentNumbers.contains(item.getIdentificationNumber()))
                            .collect(Collectors.toList());
                    if (yiRuZhang.size() > 0) {
                        String replicaResponse = "入账失败" + obd.getRuzhangTime() + "账期已存在";
                        for (OrderContrastBusinessDetail oldOCBD : yiRuZhang) {
                            oldOCBD.setRuzhangTime(obd.getRuzhangTime());
                            oldOCBD.setStatus(3);
                            oldOCBD.setResponse(replicaResponse);
                        }
                        orderContrastBusinessDetailMapper.batchUpdateByContrastRuZhang(yiRuZhang);
                        batch.removeAll(yiRuZhang);
                        logger.info("删除已入账商户订单还剩:{}", batch.size());
                    }
                }
            }

            if (batch.size() > 0) {
                Map<Long, OrderContrastSumPrice> newSumPrice = batch.stream()
                        .collect(Collectors.groupingBy(
                                OrderContrastBusinessDetail::getOrderId,
                                Collectors.collectingAndThen(Collectors.toList(),
                                        list -> {
                                            BigDecimal totalPrice = list.stream()
                                                    .map(OrderContrastBusinessDetail::getPrice)
                                                    .reduce(BigDecimal.ZERO, BigDecimal::add);
                                            return new OrderContrastSumPrice(list.get(0).getOrderId(), totalPrice, list.get(0).getPolicyName());
                                        })));
                if (newSumPrice.size() > 0) {
                    List<RxOrder> oldOrders = rxOrderMapper.selectCommissionListByIds(newSumPrice.keySet());
                    for (RxOrder old : oldOrders) {
                        OrderContrastSumPrice orderContrastSumPrice = newSumPrice.get(old.getId());
                        old.setCommissionRecent(orderContrastSumPrice.getTotalPrice());
                        BigDecimal newZongJia = old.getCommissionAccumulate().add(orderContrastSumPrice.getTotalPrice());
                        old.setCommissionAccumulate(newZongJia);
                        old.setCommissionPolicyName(orderContrastSumPrice.getPolicyName());
                    }
                    rxOrderMapper.batchUpdateByContrastRuZhang(oldOrders);
                    for (OrderContrastBusinessDetail oldOCBD : batch) {
                        oldOCBD.setRuzhangTime(obd.getRuzhangTime());
                        oldOCBD.setStatus(2);
                        oldOCBD.setResponse(SUCCESS);
                    }
                    orderContrastBusinessDetailMapper.batchUpdateByContrastRuZhang(batch);

                }
            }
        }

        rxOrderContrast.setStatus(2);
        rxOrderContrast.setRuzhangManageId(SecurityUtils.getUserId());
        rxOrderContrast.setRuzhangTime(System.currentTimeMillis() / 1000);
        rxOrderContrastMapper.updateRxOrderContrast(rxOrderContrast);
        return AjaxResult.success("入账已完成!");
    }


    //    public AjaxResult ruZhang(@RequestBody OrderContrastBusinessDetail obd) {
//        RxOrderContrast rxOrderContrast = rxOrderContrastMapper.selectRxOrderContrastByBatch(obd.getOrderContrastId());
//        if (null == rxOrderContrast) {
//            throw new ServiceException("没有查到对应的批次号");
//        }
//        OrderContrastBusinessDetail queryOBD = new OrderContrastBusinessDetail();
//        queryOBD.setOrderContrastId(obd.getOrderContrastId());
//        List<OrderContrastBusinessDetail> orderContrastBusinessDetails = orderContrastBusinessDetailMapper.selectOrderContrastBusinessDetailList(queryOBD);
//
//        if (orderContrastBusinessDetails.size() > 0) {
//            OrderContrastBusinessDetail queryObD = new OrderContrastBusinessDetail();
//            queryObD.setRuzhangTime(obd.getRuzhangTime());
//            List<OrderContrastBusinessDetail> ruZhangTimeReplicas = orderContrastBusinessDetailMapper.selectOrderContrastBusinessDetailList(queryObD);
//            if (ruZhangTimeReplicas.size() > 0) {
//                Set<String> ruZhangIdentNumbers = ruZhangTimeReplicas.stream()
//                        .map(OrderContrastBusinessDetail::getIdentificationNumber)
//                        .collect(Collectors.toSet());
//
//                List<OrderContrastBusinessDetail> yiRuZhang = orderContrastBusinessDetails.stream()
//                        .filter(item -> ruZhangIdentNumbers.contains(item.getIdentificationNumber()))
//                        .collect(Collectors.toList());
//                if (yiRuZhang.size() > 0) {
//                    String replicaResponse = "入账失败" + obd.getRuzhangTime() + "账期已存在";
//                    //循环赋值
//                    for (OrderContrastBusinessDetail oldOCBD : yiRuZhang) {
//                        oldOCBD.setRuzhangTime(obd.getRuzhangTime());
//                        oldOCBD.setStatus(3);
//                        oldOCBD.setResponse(replicaResponse);
//                    }
//                    //批量更新商户信息表
//                    orderContrastBusinessDetailMapper.batchUpdateByContrastRuZhang(yiRuZhang);
//                    //删除已入账的订单
//                    orderContrastBusinessDetails.removeAll(yiRuZhang);
//                    logger.info("删除已入账商户订单还剩:{}", orderContrastBusinessDetails.size());
//                }
//            }
//        }
//
//        if (orderContrastBusinessDetails.size() > 0) {
//            Map<Long, OrderContrastSumPrice> newSumPrice = orderContrastBusinessDetails.stream()
//                    .collect(Collectors.groupingBy(
//                            OrderContrastBusinessDetail::getOrderId,
//                            Collectors.collectingAndThen(Collectors.toList(),
//                                    list -> {
//                                        BigDecimal totalPrice = list.stream()
//                                                .map(OrderContrastBusinessDetail::getPrice)
//                                                .reduce(BigDecimal.ZERO, BigDecimal::add);
//                                        return new OrderContrastSumPrice(list.get(0).getOrderId(), totalPrice, list.get(0).getPolicyName());
//                                    })));
//            if (newSumPrice.size() > 0) {
//                List<RxOrder> oldOrders = rxOrderMapper.selectCommissionListByIds(newSumPrice.keySet());
//                for (RxOrder old : oldOrders) {
//                    OrderContrastSumPrice orderContrastSumPrice = newSumPrice.get(old.getId());
//                    old.setCommissionRecent(orderContrastSumPrice.getTotalPrice());
//                    BigDecimal newZongJia = old.getCommissionAccumulate().add(orderContrastSumPrice.getTotalPrice());
//                    old.setCommissionAccumulate(newZongJia);
//                    old.setCommissionPolicyName(orderContrastSumPrice.getPolicyName());
//                }
//                //批量订单表
//                rxOrderMapper.batchUpdateByContrastRuZhang(oldOrders);
//                //循环赋值
//                for (OrderContrastBusinessDetail oldOCBD : orderContrastBusinessDetails) {
//                    oldOCBD.setRuzhangTime(obd.getRuzhangTime());
//                    oldOCBD.setStatus(2);
//                    oldOCBD.setResponse(SUCCESS);
//                }
//                //批量更新商户信息表
//                orderContrastBusinessDetailMapper.batchUpdateByContrastRuZhang(orderContrastBusinessDetails);
//            }
//        }
//
//        //批次表更新
//        rxOrderContrast.setStatus(2);
//        rxOrderContrast.setRuzhangManageId(SecurityUtils.getUserId());
//        rxOrderContrast.setRuzhangTime(System.currentTimeMillis() / 1000);
//        rxOrderContrastMapper.updateRxOrderContrast(rxOrderContrast);
//        return AjaxResult.success("入账已完成!");
//    }


}
